<%@ page import="com.webamc.common.enums.Fields" %>
<%@ page import="com.webamc.common.enums.Params" %>
<%@ page import="com.webamc.model.User" %>
<%@ page import="com.webamc.model.UserInfo" %>
<%@ page import="java.util.List" %>
<%@ page import="static com.webamc.util.CommonUtil.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%!
    static String href = "user.html?action=view&" + Fields.USERID + "=";
%>
<link rel="stylesheet" href="../webamc.css"/>
<div class="action-header">USERS</div>
<%
    String target = request.getParameter(Params.POPUP); //this sent from Popup.jsp
    final boolean isPopup = null !=target;
    final List<User> users = (List) request.getAttribute(Params.BEAN);
    if (users == null || users.size() == 0) {
%><p class="header-divsmall">No User. <a href="user.html?action=beforeCreate">click here</a> to create.</p>
<% return;
}
%>
<jsp:include page="msgs.jsp"/>

<table class="browse-table" border="1">
    <tr>
        <th>User Id</th>
        <th>Username</th>
        <th>Name</th>
        <th>Category</th>
        <th>Status</th>                   
        <th>Address</th>
        <th>City</th>
        <th>State</th>
    </tr>

    <%
        boolean even = true;
        for (User u : users) {
            UserInfo ui = u.getUserInfo();
            even = !even;
            String idHref;
            if (isPopup) {
                idHref = "javascript:parent.selectMe( '" + target + "'," + u.getUserId() + ")";
            } else {
                idHref = href + u.getUserId();
            }
    %>
    <tr class="<%=even?"rowone":"rowtwo"%>">
        <td><%=u.getUserId()%></td>
        <td><a href="<%=idHref%>"><%=out(u.getUsername())%></a></td>
        <td><%=out(ui.getFullName())%></td>
        <td><%=out(u.getCategory())%>
        </td>
        <td><%=out(u.getStatus())%>
        </td>
        <td><%=out(ui.getAddress())%>
        </td>
        <td><%=out(ui.getCity())%>
        </td>
        <td><%=out(ui.getState())%>
        </td>
    </tr>
    <%}%>
</table>
